import Vue from 'vue'
import VueRouter from 'vue-router'
import Tabber from '../components/Tabbar.vue'
import xlyRouter from './xly-router'
import ddk from './ddk-router'
import Router from 'vue-router'
import store from '../store/index'

Vue.use(VueRouter)
import DlRouter from "./dl-router"
const routes = [
  ...DlRouter,
  ...ddk,
  ...xlyRouter
]

// const originalPush = Router.prototype.push
// Router.prototype.push = function push(location) {undefined
// return originalPush.call(this, location).catch(err => err)
// }
const router = new VueRouter({
  routes
})


const path=['/cart','/my']
router.beforeEach((to,from,next)=>{
  if(to.path.indexOf( '/cart')!=-1 || to.path.indexOf('/my')!=-1){
    if(store.state.ddk.userInfo!=null){
        next()
    }else{
        next({
          path:'/login',
         query:{
           target:to.path
         }
        })
    }
  }else{
    next()
  }
})

export default router
